package com.tfy.liquor.controller;

import com.tfy.liquor.bean.ProductImg;
import com.tfy.liquor.bean.Result;
import com.tfy.liquor.service.ProductImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品图片信息
 */
@RestController
@RequestMapping("/productImg")
public class ProductImgController {
    @Autowired
    private ProductImgService productImgService;

    // 添加产品图片
    @RequestMapping("/addProductImg")
    public Result addProductImg(ProductImg productImg) {
        if (null == productImg || null == productImg.getProductId() || null == productImg.getImgUrl()) {
            return new Result().bad_CodeIsNull();
        }
        if (productImgService.addProductImg(productImg)) {
            return new Result().ok("添加产品成功！");
        }
        return new Result().error("添加产品失败！");
    }

    // 修改产品图片状态
    @RequestMapping("/editProductImg")
    public Result editProductImg(ProductImg productImg) {
        if (null == productImg || null == productImg.getProductId() || null == productImg.getStatus()) {
            return new Result().bad_CodeIsNull();
        }
        if (productImgService.editProductImgStatus(productImg)) {
            return new Result().ok("修改状态成功！");
        }
        return new Result().error("修改状态失败！");
    }

    // 根据产品id获取图片信息
    @RequestMapping("/getProductImg")
    public Result getProductImg(String productId) {
        if (null == productId) {
            return new Result().bad_CodeIsNull();
        }
        return new Result(productImgService.getProductImg(productId)).ok();
    }
}
